package com.itheima.controller.bounty;

import com.itheima.pojo.Bounty;
import com.itheima.pojo.BountyUserParam;
import com.itheima.pojo.Result;
import com.itheima.service.BountyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;


@RequestMapping("/bounties")
@RestController
@Slf4j
public class BountyController {//
    @Autowired
    private BountyService bountyService;

    /**
     * 用户接受收任务并添加到user_bounties表中
     *
     * @param bup
     * @return
     */
    @PostMapping("/accept")
    public Result acceptBounty(@RequestBody BountyUserParam bup) {
        System.out.println(bup);
        bountyService.acceptBounty(bup);
        return Result.success();
    }

    /**
     * 用户查询悬赏任务列表
     *
     * @return
     */
    @GetMapping
    public Result list() {
        List<Bounty> bounty = bountyService.list();
        return Result.success(bounty);
    }

    /**
     * 添加
     * @param bounty
     * @return
     */
    @PostMapping
    public Result add(@RequestBody Bounty bounty){

        bountyService.add(bounty);
        return Result.success();
    }



    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id ){
        bountyService.delete(id);
        return  Result.success();
    }

    /**
     * 修改 查询回显
     * @return
     */
    @GetMapping("/{id}")
    public  Result  getbosById(@PathVariable Integer id){
        Bounty bounty=bountyService.getbosById(id);
        return Result.success(bounty);
    }


    /**
     * 修改悬赏表
     * @param bounty
     * @return
     */
    @PutMapping
    public Result updateBounty(@RequestBody Bounty bounty){
        bountyService.update(bounty);
        return Result.success();
    }


}
